<?php
class CodeSpace_Meta_Controller_Plugin_Meta extends Zend_Controller_Plugin_Abstract
{
    public function postDispatch (Zend_Controller_Request_Abstract $request)
    {
        $metaSettings = new Zend_Config_Ini(APPLICATION_PATH . '/configs/meta.ini', 'settings');
        $metaSettings = $metaSettings->toArray();
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
        $view = $viewRenderer->view;

        $view->headMeta()
            ->appendHttpEquiv('Content-Language', $view->language()->getLanguage());
        
        foreach ($metaSettings['httpequiv'] as $httpEquivKey => $httpEquivValue) {
            $view->headMeta()->appendHttpEquiv($httpEquivKey, $httpEquivValue);
        }
        
        foreach ($metaSettings['name'] as $nameKey => $nameValue) {
            $view->headMeta()->appendName($nameKey, $nameValue);
        }
        
        if ($metaSettings['bot'] == true) {
            foreach ($metaSettings['bots'] as $nameKey => $nameValue) {
                if (is_array($nameValue)) {
                    foreach ($nameValue as $value) {
                        $view->headMeta()->appendName($nameKey, $value);
                    }
                } else {
                    $view->headMeta()->appendName($nameKey, $nameValue);
                }
            }
        }
        
        $auth = Zend_Auth::getInstance();
        if ($auth->hasIdentity()) {
            $view->headMeta()
                ->appendHttpEquiv('pragma', 'no-cache')
                ->appendHttpEquiv('Cache-Control', 'no-cache');
        }
        
        $view->headMeta()->appendName('copyright', 
        	'Copyright ' . date('Y') . ', ' . $metaSettings['vendor']);
        
        $view->headMeta()->setSeparator("\n");
    }
    
}
?>